home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / Main.bin / SecurityManager.java < prev    next >
Text File  |  1998-09-22  |  33KB  |  839 lines

  1. /*
  2.  * @(#)SecurityManager.java    1.50 98/08/17
  3.  *
  4.  * Copyright 1995-1998 by Sun Microsystems, Inc.,
  5.  * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
  6.  * All rights reserved.
  7.  * 
  8.  * This software is the confidential and proprietary information
  9.  * of Sun Microsystems, Inc. ("Confidential Information").  You
  10.  * shall not disclose such Confidential Information and shall use
  11.  * it only in accordance with the terms of the license agreement
  12.  * you entered into with Sun.
  13.  */
  14.  
  15. package java.lang;
  16.  
  17. import java.io.FileDescriptor;
  18. import java.util.Hashtable;
  19. import java.net.InetAddress;
  20. import java.lang.reflect.Member;
  21.  
  22. /**
  23.  * The security manager is an abstract class that allows 
  24.  * applications to implement a security policy. It allows an 
  25.  * application to determine, before performing a possibly unsafe or 
  26.  * sensitive operation, what the operation is and whether the 
  27.  * operation is being performed by a class created via a class loader 
  28.  * rather than installed locally. Classes loaded via a class loader 
  29.  * (especially if they have been downloaded over a network) may be 
  30.  * less trustworthy than classes from files installed locally. The 
  31.  * application can allow or disallow the operation. 
  32.  * <p>
  33.  * The <code>SecurityManager</code> class contains many methods with 
  34.  * names that begin with the word <code>check</code>. These methods 
  35.  * are called by various methods in the Java libraries before those 
  36.  * methods perform certain potentially sensitive operations. The 
  37.  * invocation of such a check method typically looks like this: 
  38.  * <p><blockquote><pre>
  39.  *     SecurityManager security = System.getSecurityManager();
  40.  *     if (security != null) {
  41.  *         security.check</code><i>XXX</i><code>(argument,  . . . );
  42.  *     }
  43.  * </pre></blockquote>
  44.  * <p>
  45.  * The security manager is thereby given an opportunity to prevent 
  46.  * completion of the operation by throwing an exception. A security 
  47.  * manager routine simply returns if the operation is permitted, but 
  48.  * throws a <code>SecurityException</code> if the operation is not 
  49.  * permitted. The only exception to this convention is 
  50.  * <code>checkTopLevelWindow</code>, which returns a 
  51.  * <code>boolean</code> value. 
  52.  * <p>
  53.  * The current security manager is set by the 
  54.  * <code>setSecurityManager</code> method in class 
  55.  * <code>System</code>. The current security manager is obtained 
  56.  * by the <code>getSecurityManager</code> method. 
  57.  * <p>
  58.  * The default implementation of each of the 
  59.  * <code>check</code><i>XXX</i> methods is to assume that the caller 
  60.  * does <i>not</i> have permission to perform the requested operation. 
  61.  *
  62.  * @author  Arthur van Hoff
  63.  * @version 1.50, 08/17/98
  64.  * @see     java.lang.ClassLoader
  65.  * @see     java.lang.SecurityException
  66.  * @see     java.lang.SecurityManager#checkTopLevelWindow(java.lang.Object)
  67.  * @see     java.lang.System#getSecurityManager()
  68.  * @see     java.lang.System#setSecurityManager(java.lang.SecurityManager)
  69.  * @since   JDK1.0
  70.  */
  71. public abstract
  72. class SecurityManager {
  73.    /**
  74.      * This field is <code>true</code> if there is a security check in 
  75.      * progress; <code>false</code> otherwise. 
  76.      *
  77.      * @since   JDK1.0
  78.      */
  79.     protected boolean inCheck;
  80.  
  81.     /* 
  82.      * Have we been initialized. Effective against finalizer attacks.
  83.      */
  84.     private boolean initialized = false;
  85.  
  86.     /** 
  87.      * Tests if there is a security check in progress.
  88.      *
  89.      * @return  the value of the <code>inCheck</code> field. This field should
  90.      *          contain <code>true</code> if a security check is in progress;
  91.      *          <code>false</code> otherwise.
  92.      * @see     java.lang.SecurityManager#inCheck
  93.      * @since   JDK1.0
  94.      */
  95.     public boolean getInCheck() {
  96.     return inCheck;
  97.     }
  98.  
  99.     /**
  100.      * Constructs a new <code>SecurityManager</code>. An application is 
  101.      * not allowed to create a new security manager if there is already a 
  102.      * current security manager. 
  103.      *
  104.      * @exception  SecurityException  if a security manager already exists.
  105.      * @see        java.lang.System#getSecurityManager()
  106.      * @since      JDK1.0
  107.      */
  108.     protected SecurityManager() {
  109.     if (System.getSecurityManager() != null) {
  110.         throw new SecurityException("security manager already installed.");
  111.     }
  112.     initialized = true;
  113.     }
  114.  
  115.     /**
  116.      * Returns the current execution stack as an array of classes. 
  117.      * <p>
  118.      * The length of the array is the number of methods on the execution 
  119.      * stack. The element at index <code>0</code> is the class of the 
  120.      * currently executing method, the element at index <code>1</code> is 
  121.      * the class of that method's caller, and so on. 
  122.      *
  123.      * @return  the execution stack.
  124.      * @since   JDK1.0
  125.      */
  126.     protected native Class[] getClassContext();
  127.  
  128.     /**
  129.      * Returns an object describing the most recent class loader executing
  130.      * on the stack. 
  131.      *
  132.      * @return  the class loader of the most recent occurrence on the stack
  133.      *          of a method from a class defined using a class loader;
  134.      *          returns <code>null</code> if there is no occurrence on the
  135.      *          stack of a method from a class defined using a class loader.
  136.      * @since   JDK1.0
  137.      */
  138.     protected native ClassLoader currentClassLoader();
  139.  
  140.     /**
  141.      * Returns the current Class with a ClassLoader on the execution stack.
  142.      *
  143.      * @since   JDK1.1
  144.      */
  145.     protected Class currentLoadedClass() {
  146.     return currentLoadedClass0();    
  147.     }
  148.  
  149.     /**
  150.      * Returns the stack depth of the specified class. 
  151.      *
  152.      * @param   name   the fully qualified name of the class to search for.
  153.      * @return  the depth on the stack frame of the first occurrence of a
  154.      *          method from a class with the specified name;
  155.      *          <code>-1</code> if such a frame cannot be found.
  156.      * @since   JDK1.0
  157.      */
  158.     protected native int classDepth(String name);
  159.  
  160.     /**
  161.      * Returns the stack depth of the most recently executing method 
  162.      * from a class defined using a class loader. 
  163.      *
  164.      * @return  the depth on the stack frame of the most recent occurrence of a
  165.      *          method from a class defined using a class loader; returns
  166.      *          <code>-1</code> if there is no occurrence of a method from
  167.      *          a class defined using a class loader.
  168.      * @since   JDK1.0
  169.      */
  170.     protected native int classLoaderDepth();
  171.  
  172.     /**
  173.      * Tests if the specified String is in this Class. 
  174.      *
  175.      * @param   name   the fully qualified name of the class.
  176.      * @return  <code>true</code> if a method from a class with the specified
  177.      *          name is on the execution stack; <code>false</code> otherwise.
  178.      * @since   JDK1.0
  179.      */
  180.     protected boolean inClass(String name) {
  181.     return classDepth(name) >= 0;
  182.     }
  183.  
  184.     /**
  185.      * Tests if the current ClassLoader is equal to
  186.      * <code>null</code>.
  187.      *
  188.      * @return  <code>true</code> if a method from a class defined using a
  189.      *          class loader is on the execution stack.
  190.      * @since   JDK1.0
  191.      */
  192.     protected boolean inClassLoader() {
  193.     return currentClassLoader() != null;
  194.     }
  195.  
  196.     /**
  197.      * Creates an object that encapsulates the current execution 
  198.      * environment. The result of this method is used by the 
  199.      * three-argument <code>checkConnect</code> method and by the 
  200.      * two-argument <code>checkRead</code> method. 
  201.      * <p>
  202.      * These methods are needed because a trusted method may be called 
  203.      * on to read a file or open a socket on behalf of another method. 
  204.      * The trusted method needs to determine if the other (possibly 
  205.      * untrusted) method would be allowed to perform the operation on its 
  206.      * own. 
  207.      *
  208.      * @return  an implementation-dependent object that encapsulates
  209.      *          sufficient information about the current execution environment
  210.      *          to perform some security checks later.
  211.      * @see     java.lang.SecurityManager#checkConnect(java.lang.String, int, java.lang.Object)
  212.      * @see     java.lang.SecurityManager#checkRead(java.lang.String, java.lang.Object)
  213.      * @since   JDK1.0
  214.      */
  215.     public Object getSecurityContext() {
  216.     return null;
  217.     }
  218.  
  219.     /**
  220.      * Throws a <code>SecurityException</code> if the 
  221.      * calling thread is not allowed to create a new class loader. 
  222.      * <p>
  223.      * The <code>checkCreateClassLoader</code> method for class 
  224.      * <code>SecurityManager</code> always throws a 
  225.      * <code>SecurityException</code>. 
  226.      *
  227.      * @exception  SecurityException  if the caller does not have permission
  228.      *             to create a new class loader.
  229.      * @see        java.lang.ClassLoader#ClassLoader()
  230.      * @since      JDK1.0
  231.      */
  232.     public void checkCreateClassLoader() {
  233.     throw new SecurityException();
  234.     }
  235.     
  236.     /**
  237.      * Throws a <code>SecurityException</code> if the 
  238.      * calling thread is not allowed to modify the thread argument. 
  239.      * <p>
  240.      * This method is invoked for the current security manager by the 
  241.      * <code>stop</code>, <code>suspend</code>, <code>resume</code>, 
  242.      * <code>setPriority</code>, <code>setName</code>, and 
  243.      * <code>setDaemon</code> methods of class <code>Thread</code>. 
  244.      * <p>
  245.      * The <code>checkAccess</code> method for class 
  246.      * <code>SecurityManager</code> always throws a 
  247.      * <code>SecurityException</code>. 
  248.      *
  249.      * @param      g   the thread to be checked.
  250.  
  251.      * @exception  SecurityException  if the caller does not have permission
  252.      *               to modify the thread.
  253.      * @see        java.lang.System#getSecurityManager()
  254.      * @see        java.lang.Thread#resume()
  255.      * @see        java.lang.Thread#setDaemon(boolean)
  256.      * @see        java.lang.Thread#setName(java.lang.String)
  257.      * @see        java.lang.Thread#setPriority(int)
  258.      * @see        java.lang.Thread#stop()
  259.      * @see        java.lang.Thread#suspend()
  260.      * @since      JDK1.0
  261.      */
  262.     public void checkAccess(Thread g) {
  263.     throw new SecurityException();
  264.     }
  265.  
  266.     /**
  267.      * Throws a <code>SecurityException</code> if the 
  268.      * calling thread is not allowed to modify the thread group argument. 
  269.      * <p>
  270.      * This method is invoked for the current security manager when a 
  271.      * new child thread or child thread group is created, and by the 
  272.      * <code>setDaemon</code>, <code>setMaxPriority</code>, 
  273.      * <code>stop</code>, <code>suspend</code>, <code>resume</code>, and 
  274.      * <code>destroy</code> methods of class <code>ThreadGroup</code>. 
  275.      * <p>
  276.      * The <code>checkAccess</code> method for class 
  277.      * <code>SecurityManager</code> always throws a 
  278.      * <code>SecurityException</code>. 
  279.      *
  280.      * @param      g   the thread group to be checked.
  281.      * @exception  SecurityException  if the caller does not have permission
  282.      *               to modify the thread group.
  283.      * @see        java.lang.System#getSecurityManager()
  284.      * @see        java.lang.ThreadGroup#destroy()
  285.      * @see        java.lang.ThreadGroup#resume()
  286.      * @see        java.lang.ThreadGroup#setDaemon(boolean)
  287.      * @see        java.lang.ThreadGroup#setMaxPriority(int)
  288.      * @see        java.lang.ThreadGroup#stop()
  289.      * @see        java.lang.ThreadGroup#suspend()
  290.      * @since      JDK1.0
  291.      */
  292.     public void checkAccess(ThreadGroup g) {
  293.     throw new SecurityException();
  294.     }
  295.  
  296.     /**
  297.      * Throws a <code>SecurityException</code> if the 
  298.      * calling thread is not allowed to cause the Java Virtual Machine to 
  299.      * halt with the specified status code. 
  300.      * <p>
  301.      * This method is invoked for the current security manager by the 
  302.      * <code>exit</code> method of class <code>Runtime</code>. A status 
  303.      * of <code>0</code> indicates success; other values indicate various 
  304.      * errors. 
  305.      * <p>
  306.      * The <code>checkExit</code> method for class 
  307.      * <code>SecurityManager</code> always throws a 
  308.      * <code>SecurityException</code>. 
  309.      *
  310.      * @param      status   the exit status.
  311.      * @exception  SecurityException  if the caller does not have permission
  312.      *               to halt the Java Virtual Machine with the specified status.
  313.      * @see        java.lang.Runtime#exit(int)
  314.      * @see        java.lang.System#getSecurityManager()
  315.      * @since      JDK1.0
  316.      */
  317.     public void checkExit(int status) {
  318.     throw new SecurityException();
  319.     }
  320.  
  321.     /**
  322.      * Throws a <code>SecurityException</code> if the 
  323.      * calling thread is not allowed to create a subprocess. 
  324.      * <p>
  325.      * This method is invoked for the current security manager by the 
  326.      * <code>exec</code> methods of class <code>Runtime</code>.
  327.      * <p>
  328.      * The <code>checkExec</code> method for class 
  329.      * <code>SecurityManager</code> always throws a 
  330.      * <code>SecurityException</code>. 
  331.      *
  332.      * @param      cmd   the specified system command.
  333.      * @exception  SecurityException  if the caller does not have permission
  334.      *               to create a subprocess.
  335.      * @see        java.lang.Runtime#exec(java.lang.String)
  336.      * @see        java.lang.Runtime#exec(java.lang.String, java.lang.String[])
  337.      * @see        java.lang.Runtime#exec(java.lang.String[])
  338.      * @see        java.lang.Runtime#exec(java.lang.String[], java.lang.String[])
  339.      * @see        java.lang.System#getSecurityManager()
  340.      * @since      JDK1.0
  341.      */
  342.     public void checkExec(String cmd) {
  343.     throw new SecurityException();
  344.     }
  345.  
  346.     /**
  347.      * Throws a <code>SecurityException</code> if the 
  348.      * calling thread is not allowed to dynamic link the library code 
  349.      * specified by the string argument file. The argument is either a 
  350.      * simple library name or a complete filename. 
  351.      * <p>
  352.      * This method is invoked for the current security manager by 
  353.      * methods <code>load</code> and <code>loadLibrary</code> of class 
  354.      * <code>Runtime</code>. 
  355.      * <p>
  356.      * The <code>checkLink</code> method for class 
  357.      * <code>SecurityManager</code> always throws a 
  358.      * <code>SecurityException</code>. 
  359.      *
  360.      * @param      lib   the name of the library.
  361.      * @exception  SecurityException  if the caller does not have permission
  362.      *               to dynamically link the library.
  363.      * @see        java.lang.Runtime#load(java.lang.String)
  364.      * @see        java.lang.Runtime#loadLibrary(java.lang.String)
  365.      * @see        java.lang.System#getSecurityManager()
  366.      * @since      JDK1.0
  367.      */
  368.     public void checkLink(String lib) {
  369.     throw new SecurityException();
  370.     }
  371.  
  372.     /**
  373.      * Throws a <code>SecurityException</code> if the 
  374.      * calling thread is not allowed to read from the specified file 
  375.      * descriptor. 
  376.      * <p>
  377.      * The <code>checkRead</code> method for class 
  378.      * <code>SecurityManager</code> always throws a 
  379.      * <code>SecurityException</code>. 
  380.      *
  381.      * @param      fd   the system-dependent file descriptor.
  382.      * @exception  SecurityException  if the caller does not have permission
  383.      *               to access the specified file descriptor.
  384.      * @see        java.io.FileDescriptor
  385.      * @since      JDK1.0
  386.      */
  387.     public void checkRead(FileDescriptor fd) {
  388.     throw new SecurityException();
  389.     }
  390.  
  391.     /**
  392.      * Throws a <code>SecurityException</code> if the 
  393.      * calling thread is not allowed to read the file specified by the 
  394.      * string argument. 
  395.      * <p>
  396.      * The <code>checkRead</code> method for class 
  397.      * <code>SecurityManager</code> always throws a 
  398.      * <code>SecurityException</code>. 
  399.      *
  400.      * @param      file   the system-dependent file name.
  401.      * @exception  SecurityException  if the caller does not have permission
  402.      *               to access the specified file.
  403.      * @since   JDK1.0
  404.      */
  405.     public void checkRead(String file) {
  406.     throw new SecurityException();
  407.     }
  408.  
  409.     /**
  410.      * Throws a <code>SecurityException</code> if the 
  411.      * specified security context is not allowed to read the file 
  412.      * specified by the string argument. The context must be a security 
  413.      * context returned by a previous call to 
  414.      * <code>getSecurityContext</code>. 
  415.      * <p>
  416.      * The <code>checkRead</code> method for class 
  417.      * <code>SecurityManager</code> always throws a 
  418.      * <code>SecurityException</code>. 
  419.      *
  420.      * @param      file      the system-dependent filename.
  421.      * @param      context   a system-dependent security context.
  422.      * @exception  SecurityException  if the specified security context does
  423.      *               not have permission to read the specified file.
  424.      * @see        java.lang.SecurityManager#getSecurityContext()
  425.      * @since      JDK1.0
  426.      */
  427.     public void checkRead(String file, Object context) {
  428.     throw new SecurityException();
  429.     }
  430.  
  431.     /**
  432.      * Throws a <code>SecurityException</code> if the 
  433.      * calling thread is not allowed to write to the specified file 
  434.      * descriptor. 
  435.      * <p>
  436.      * The <code>checkWrite</code> method for class 
  437.      * <code>SecurityManager</code> always throws a 
  438.      * <code>SecurityException</code>. 
  439.      *
  440.      * @param      fd   the system-dependent file descriptor.
  441.      * @exception  SecurityException  if the caller does not have permission
  442.      *               to access the specified file descriptor.
  443.      * @see        java.io.FileDescriptor
  444.      * @since      JDK1.0
  445.      */
  446.     public void checkWrite(FileDescriptor fd) {
  447.     throw new SecurityException();
  448.     }
  449.  
  450.     /**
  451.      * Throws a <code>SecurityException</code> if the 
  452.      * calling thread is not allowed to write to the file specified by 
  453.      * the string argument. 
  454.      * <p>
  455.      * The <code>checkWrite</code> method for class 
  456.      * <code>SecurityManager</code> always throws a 
  457.      * <code>SecurityException</code>. 
  458.      *
  459.      * @param      file   the system-dependent filename.
  460.      * @exception  SecurityException  if the caller does not have permission
  461.      *               to access the specified file.
  462.      * @since   JDK1.0
  463.      */
  464.     public void checkWrite(String file) {
  465.     throw new SecurityException();
  466.     }
  467.  
  468.     /**
  469.      * Throws a <code>SecurityException</code> if the 
  470.      * calling thread is not allowed to delete the specified file. 
  471.      * <p>
  472.      * This method is invoked for the current security manager by the 
  473.      * <code>delete</code> method of class <code>File</code>.
  474.      * <p>
  475.      * The <code>checkDelete</code> method for class 
  476.      * <code>SecurityManager</code> always throws a 
  477.      * <code>SecurityException</code>. 
  478.      *
  479.      * @param      file   the system-dependent filename.
  480.      * @exception  SecurityException  if the caller does not have permission
  481.      *               to delete the file.
  482.      * @see        java.io.File#delete()
  483.      * @see        java.lang.System#getSecurityManager()
  484.      * @since      JDK1.0
  485.      */
  486.     public void checkDelete(String file) {
  487.     throw new SecurityException();
  488.     }
  489.  
  490.     /**
  491.      * Throws a <code>SecurityException</code> if the 
  492.      * calling thread is not allowed to open a socket connection to the 
  493.      * specified host and port number. 
  494.      * <p>
  495.      * A port number of <code>-1</code> indicates that the calling 
  496.      * method is attempting to determine the IP address of the specified 
  497.      * host name. 
  498.      * <p>
  499.      * The <code>checkConnect</code> method for class 
  500.      * <code>SecurityManager</code> always throws a 
  501.      * <code>SecurityException</code>. 
  502.      *
  503.      * @param      host   the host name port to connect to.
  504.      * @param      port   the protocol port to connect to.
  505.      * @exception  SecurityException  if the caller does not have permission
  506.      *               to open a socket connection to the specified
  507.      *               <code>host</code> and <code>port</code>.
  508.      * @since      JDK1.0
  509.      */
  510.     public void checkConnect(String host, int port) {
  511.     throw new SecurityException();
  512.     }
  513.  
  514.     /**
  515.      * Throws a <code>SecurityException</code> if the 
  516.      * specified security context is not allowed to open a socket 
  517.      * connection to the specified host and port number. 
  518.      * <p>
  519.      * A port number of <code>-1</code> indicates that the calling 
  520.      * method is attempting to determine the IP address of the specified 
  521.      * host name. 
  522.      * <p>
  523.      * The <code>checkConnect</code> method for class 
  524.      * <code>SecurityManager</code> always throws a 
  525.      * <code>SecurityException</code>. 
  526.      *
  527.      * @param      host      the host name port to connect to.
  528.      * @param      port      the protocol port to connect to.
  529.      * @param      context   a system-dependent security context.
  530.      * @exception  SecurityException  if the specified security context does
  531.      *               not have permission to open a socket connection to the
  532.      *               specified <code>host</code> and <code>port</code>.
  533.      * @see        java.lang.SecurityManager#getSecurityContext()
  534.      * @since      JDK1.0
  535.      */
  536.     public void checkConnect(String host, int port, Object context) {
  537.     throw new SecurityException();
  538.     }
  539.  
  540.     /**
  541.      * Throws a <code>SecurityException</code> if the 
  542.      * calling thread is not allowed to wait for a connection request on 
  543.      * the specified local port number. 
  544.      * <p>
  545.      * The <code>checkListen</code> method for class 
  546.      * <code>SecurityManager</code> always throws a 
  547.      * <code>SecurityException</code>. 
  548.      *
  549.      * @param      port   the local port.
  550.      * @exception  SecurityException  if the caller does not have permission
  551.      *               to listen on the specified port.
  552.      * @since   JDK1.0
  553.      */
  554.     public void checkListen(int port) {
  555.     throw new SecurityException();
  556.     }
  557.  
  558.     /**
  559.      * Throws a <code>SecurityException</code> if the 
  560.      * calling thread is not permitted to accept a socket connection from 
  561.      * the specified host and port number. 
  562.      * <p>
  563.      * This method is invoked for the current security manager by the 
  564.      * <code>accept</code> method of class <code>ServerSocket</code>. 
  565.      * <p>
  566.      * The <code>checkAccept</code> method for class 
  567.      * <code>SecurityManager</code> always throws a
  568.      * <code>SecurityException</code>. 
  569.      *
  570.      * @param      host   the host name of the socket connection.
  571.      * @param      port   the port number of the socket connection.
  572.      * @exception  SecurityException  if the caller does not have permission
  573.      *               to accept the connection.
  574.      * @see        java.lang.System#getSecurityManager()
  575.      * @see        java.net.ServerSocket#accept()
  576.      * @since      JDK1.0
  577.      */
  578.     public void checkAccept(String host, int port) {
  579.     throw new SecurityException();
  580.     }
  581.  
  582.     /**
  583.      * Tests if current execution context is allowed to use
  584.      * (join/leave/send/receive) IP multicast.
  585.      *
  586.      * @param      multicast  Internet group address to be used.
  587.      * @exception  SecurityException  if a security error has occurred.
  588.      * @since      JDK1.1
  589.      */
  590.     public void checkMulticast(InetAddress maddr) {
  591.     throw new SecurityException();
  592.     }
  593.  
  594.     /**
  595.      * Tests to see if current execution context is allowed to use
  596.      * (join/leave/send/receive) IP multicast.
  597.      *
  598.      * @param      multicast  Internet group address to be used.
  599.      * @param      ttl        value in use, if it is multicast send.
  600.      * @exception  SecurityException  if a security error has occurred.
  601.      * @since      JDK1.1
  602.      */
  603.     public void checkMulticast(InetAddress maddr, byte ttl) {
  604.     throw new SecurityException();
  605.     }
  606.  
  607.     /**
  608.      * Throws a <code>SecurityException</code> if the 
  609.      * calling thread is not allowed to access or modify the system 
  610.      * properties. 
  611.      * <p>
  612.      * This method is used by the <code>getProperties</code> and 
  613.      * <code>setProperties</code> methods of class <code>System</code>. 
  614.      * <p>
  615.      * The <code>checkPropertiesAccess</code> method for class 
  616.      * <code>SecurityManager</code> always throws a 
  617.      * <code>SecurityException</code>. 
  618.      *
  619.      * @exception  SecurityException  if the caller does not have permission
  620.      *               to access or modify the system properties.
  621.      * @see        java.lang.System#getProperties()
  622.      * @see        java.lang.System#setProperties(java.util.Properties)
  623.      * @since      JDK1.0
  624.      */
  625.     public void checkPropertiesAccess() {
  626.     throw new SecurityException();
  627.     }
  628.  
  629.     /**
  630.      * Throws a <code>SecurityException</code> if the 
  631.      * calling thread is not allowed to access the system property with 
  632.      * the specified <code>key</code> name. 
  633.      * <p>
  634.      * This method is used by the <code>getProperty</code> method of 
  635.      * class <code>System</code>. 
  636.      * <p>
  637.      * The <code>checkPropertiesAccess</code> method for class 
  638.      * <code>SecurityManager</code> always throws a 
  639.      * <code>SecurityException</code>. 
  640.      *
  641.      * @param      key   a system property key.
  642.      * @exception  SecurityException  if the caller does not have permission
  643.      *               to access the specified system property.
  644.      * @see        java.lang.System#getProperty(java.lang.String)
  645.      * @since      JDK1.0
  646.      */
  647.     public void checkPropertyAccess(String key) {
  648.     throw new SecurityException();
  649.     }
  650.  
  651.     /**
  652.      * Returns <code>false</code> if the calling 
  653.      * thread is not trusted to bring up the top-level window indicated 
  654.      * by the <code>window</code> argument. In this case, the caller can 
  655.      * still decide to show the window, but the window should include 
  656.      * some sort of visual warning. If the method returns 
  657.      * <code>true</code>, then the window can be shown without any 
  658.      * special restrictions. 
  659.      * <p>
  660.      * See class <code>Window</code> for more information on trusted and 
  661.      * untrusted windows. 
  662.      * <p>
  663.      * The <code>checkSetFactory</code> method for class 
  664.      * <code>SecurityManager</code> always returns <code>false</code>. 
  665.      *
  666.      * @param      window   the new window that is being created.
  667.      * @return     <code>true</code> if the caller is trusted to put up
  668.      *             top-level windows; <code>false</code> otherwise.
  669.      * @exception  SecurityException  if creation is disallowed entirely.
  670.      * @see        java.awt.Window
  671.      * @since      JDK1.0
  672.      */
  673.     public boolean checkTopLevelWindow(Object window) {
  674.     return false;
  675.     }
  676.  
  677.     /**
  678.      * Tests if a client can initiate a print job request.
  679.      *
  680.      * @since   JDK1.1
  681.      */
  682.     public void checkPrintJobAccess() {
  683.       throw new SecurityException();
  684.     }
  685.  
  686.     /**
  687.      * Tests if a client can get access to the system clipboard.
  688.      *
  689.      * @since   JDK1.1
  690.      */
  691.     public void checkSystemClipboardAccess() {
  692.       throw new SecurityException();
  693.     }
  694.  
  695.     /**
  696.      * Tests if a client can get access to the AWT event queue.
  697.      *
  698.      * @since   JDK1.1
  699.      */
  700.     public void checkAwtEventQueueAccess() {
  701.       throw new SecurityException();
  702.     }
  703.  
  704.     /**
  705.      * Throws a <code>SecurityException</code> if the 
  706.      * calling thread is not allowed to access the package specified by 
  707.      * the argument. 
  708.      * <p>
  709.      * This method is used by the <code>loadClass</code> method of class 
  710.      * loaders. 
  711.      * <p>
  712.      * The <code>checkPackageAccess</code> method for class 
  713.      * <code>SecurityManager</code> always throws a 
  714.      * <code>SecurityException</code>. 
  715.      *
  716.      * @param      pkg   the package name.
  717.      * @exception  SecurityException  if the caller does not have permission
  718.      *               to access the specified package.
  719.      * @see        java.lang.ClassLoader#loadClass(java.lang.String, boolean)
  720.      * @since      JDK1.0
  721.      */
  722.     public void checkPackageAccess(String pkg) {
  723.     throw new SecurityException();
  724.     }
  725.  
  726.     /**
  727.      * Throws a <code>SecurityException</code> if the 
  728.      * calling thread is not allowed to define classes in the package 
  729.      * specified by the argument. 
  730.      * <p>
  731.      * This method is used by the <code>loadClass</code> method of some 
  732.      * class loaders. 
  733.      * <p>
  734.      * The <code>checkPackageDefinition</code> method for class 
  735.      * <code>SecurityManager</code> always throws a 
  736.      * <code>SecurityException</code>. 
  737.      *
  738.      * @param      pkg   the package name.
  739.      * @exception  SecurityException  if the caller does not have permission
  740.      *               to define classes in the specified package.
  741.      * @see        java.lang.ClassLoader#loadClass(java.lang.String, boolean)
  742.      * @since      JDK1.0
  743.      */
  744.     public void checkPackageDefinition(String pkg) {
  745.     throw new SecurityException();
  746.     }
  747.  
  748.     /**
  749.      * Throws a <code>SecurityException</code> if the 
  750.      * calling thread is not allowed to set the socket factory used by 
  751.      * <code>ServerSocket</code> or <code>Socket</code>, or the stream 
  752.      * handler factory used by <code>URL</code>. 
  753.      * <p>
  754.      * The <code>checkSetFactory</code> method for class 
  755.      * <code>SecurityManager</code> always throws a 
  756.      * <code>SecurityException</code>. 
  757.      *
  758.      * @exception  SecurityException  if the caller does not have permission
  759.      *               to specify a socket factory or a stream handler factory.
  760.      * @see        java.net.ServerSocket#setSocketFactory(java.net.SocketImplFactory)
  761.      * @see        java.net.Socket#setSocketImplFactory(java.net.SocketImplFactory)
  762.      * @see        java.net.URL#setURLStreamHandlerFactory(java.net.URLStreamHandlerFactory)
  763.      * @since      JDK1.0
  764.      */
  765.     public void checkSetFactory() {
  766.     throw new SecurityException();
  767.     }
  768.  
  769.     /**
  770.      * Tests if a client is allowed to access members. If access is
  771.      * denied, throw a SecurityException.
  772.      * The default policy is to deny all accesses.
  773.      *
  774.      * @since JDK1.1
  775.      */
  776.     public void checkMemberAccess(Class clazz, int which) {
  777.     throw new SecurityException();
  778.     }
  779.  
  780.     /**
  781.      * Tests access to certain operations for a security API
  782.      * action.
  783.      *
  784.      * @since   JDK1.1
  785.      */
  786.     public void checkSecurityAccess(String action) {
  787.     throw new SecurityException();
  788.     }
  789.  
  790.     private native Class currentLoadedClass0();
  791.  
  792.     /**
  793.      * Returns the thread group into which to instantiate any new
  794.      * thread being created at the time this is being called.
  795.      * By default, it returns the thread group of the current
  796.      * thread. This should be overriden by specific security
  797.      * manager to return the appropriate thread group.
  798.      *
  799.      * @since   JDK1.1
  800.      */
  801.     public ThreadGroup getThreadGroup() {
  802.     return Thread.currentThread().getThreadGroup();
  803.     }
  804.  
  805. }    
  806.  
  807. class NullSecurityManager extends SecurityManager {
  808.     public void checkCreateClassLoader() { } 
  809.     public void checkAccess(Thread g) { }
  810.     public void checkAccess(ThreadGroup g) { }
  811.     public void checkExit(int status) { }
  812.     public void checkExec(String cmd) { }
  813.     public void checkLink(String lib) { }
  814.     public void checkRead(FileDescriptor fd) { }
  815.     public void checkRead(String file) { }
  816.     public void checkRead(String file, Object context) { }
  817.     public void checkWrite(FileDescriptor fd) { }
  818.     public void checkWrite(String file) { }
  819.     public void checkDelete(String file) { }
  820.     public void checkConnect(String host, int port) { }
  821.     public void checkConnect(String host, int port, Object context) { }
  822.     public void checkListen(int port) { }
  823.     public void checkAccept(String host, int port) { }
  824.     public void checkMulticast(InetAddress maddr) { }
  825.     public void checkMulticast(InetAddress maddr, byte ttl) { }
  826.     public void checkPropertiesAccess() { }
  827.     public void checkPropertyAccess(String key) { }
  828.     public void checkPropertyAccess(String key, String def) { }
  829.     public boolean checkTopLevelWindow(Object window) { return true; }
  830.     public void checkPrintJobAccess() { }
  831.     public void checkSystemClipboardAccess() { }
  832.     public void checkAwtEventQueueAccess() { }
  833.     public void checkPackageAccess(String pkg) { }
  834.     public void checkPackageDefinition(String pkg) { }
  835.     public void checkSetFactory() { }
  836.     public void checkMemberAccess(Class clazz, int which) { }
  837.     public void checkSecurityAccess(String provider) { }
  838. }    
  839.